#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'AWS/EC2'
require 'basic_configuration'
require 'aws_context'
require 'pp'

# Display infrmation about a given instance.

if ARGV[0] == '-?' || ARGV.size != 1 then
  puts "usage: list-instance instance-name"
  exit 1
end
name=ARGV[0]

Signal.trap("INT") do
  exit 2
end

config = BasicConfiguration.new
ec2 = AwsContext.instance.ec2(*config.keys)
begin
  instances = ec2.describe_instances([name])
  #pp instances
  instances.each  do |i| 
    i[:instances].each do |o| 
      puts "#{o[:id]}"
      puts "#{o[:public_dns]}"
      puts "#{o[:state]}"
      puts "#{o[:image_id]}"
      puts "#{o[:launch_time]}"
      puts "#{i[:groups].join(' ')}"
    end
  end
rescue
  puts "error #{$!} #{name}"
  exit 1
end

